import {
  getList as getMesSalesOrderList,
  getOrderStatusList,
  getFactoryCodeList as getMesSalesOrderFactoryCodeList,
  getLineCodeListNew,
} from "@/api/order/mesProdOrderPlan";

export const mesSalesOrderDialog = {
  data() {
    return {
      mesSalesOrderDialogVisible: false, //表格弹框隐藏显示
      getMesSalesOrderList, // 获取弹框数据接口
      hasMesSalesOrderFooter: true, // 是否需要底部按钮默认true
      mesSalesOrderSearchDialog: {
        inline: true,
        formDesc: {
          // saleCode: {
          //   type: 'input',
          //   label: '销售订单编码',
          // },
          planCode: {
            type: "input",
            layout: 8,
            label: $i18n.t("mesProdOrder.productionOrderCode"),
          },
          // prodCode: {
          //   type: 'input',
          //   label: '产品编码',
          // },
          // prodName: {
          //   type: 'input',
          //   label: '产品名称',
          // },
          // prodOrderType: {
          //   type: 'select',
          //   label: '生产订单类型',
          //   prop: {
          //     value: "value",
          //     text: "description",
          //   },
          //   options: async (data) => {
          //     const list = await getProdOrderTypeList()
          //     return list.data.result
          //   },
          // },
          // planBeginDate: {
          //   type: 'daterange',
          //
          //   label: '计划开始日期',
          //   attrs: {
          //     valueFormat: "yyyy-MM-dd",
          //     searchArrKey: ["planBeginDateMin", "planBeginDateMax"]
          //   },
          // },
          orderStatus: {
            type: "select",
            label: $i18n.t("mesProdOrder.orderStatu3"),
            layout: 8,
            prop: {
              value: "value",
              text: "description",
            },
            options: async (data) => {
              const list = await getOrderStatusList();
              return list.data.result;
            },
          },
          // lineName: {
          //   type: 'input',
          //   label: '线体名称',
          // },
        },
      },
      mesSalesOrderDialogColumn: [
        {
          type: "selection",
        },
        {
          type: "index",
          label: $i18n.t("common.order"),
          width: 60,
          fixed: "left",
        },

        {
          prop: "planCode",
          label: $i18n.t("mesProdOrder.productionOrderCode"),
          width: 180,
          showOverflowTooltip: true,
        },
        //        {
        //          prop: "saleCode",
        //          label: "销售订单编码",
        //          width: 180,
        //          showOverflowTooltip: true,
        //        },

        {
          prop: "prodCode",
          label: $i18n.t("mesProdOrder.prodCode"),
          width: 180,
          showOverflowTooltip: true,
        },
        {
          prop: "prodName",
          label: $i18n.t("mesProdOrder.prodName"),
          width: 230,
          showOverflowTooltip: true,
        },
        // {
        //   prop: "priority",
        //   label: "订单优先级",
        //   width: 120,
        // },
        {
          prop: "quantity",
          label: $i18n.t("mesProdOrder.planQuantity"),
          minWidth: 120,
        },
        {
          prop: "actualQuantity",
          label: $i18n.t("mesProdOrder.actualQuantity"),
          minWidth: 120,
        },
        {
          prop: "planBeginDate",
          label: $i18n.t("mesProdOrder.planBeginDate"),
          width: 130,
        },

        {
          prop: "orderStatus",
          label: $i18n.t("mesProdOrder.orderStatu3"),
          minWidth: 100,
          optionProp: {
            value: "value",
            label: "description",
          },
          option: async (data) => {
            const list = await getOrderStatusList();
            return list.data.result;
          },
        },

        // {
        //   prop: "lineName",
        //   label: "线体名称",
        //   minWidth: 200,
        // },
        // {
        //   prop: "remark",
        //   label: "备注",
        // },

        {
          prop: "createTime",
          label: $i18n.t("common.createTime"),
          width: 180,
        },

        {
          prop: "updateTime",
          label: $i18n.t("common.updateTime"),
          width: 180,
        },
      ],
    };
  },
  methods: {
    // 弹框表格，双击表格，或者点击确定 返回选中数据
    getSelectMesSalesOrder(data) {
      this.$refs.formDrawer.formKey = Date.now();
      let {
        planCode,
        saleCode,
        prodCode,
        prodOrderType,
        deliveryDate,
        slackTime,
        prodName,
        seriesName,
        seriesCode,
        unit,
        unitCode,
        batchNo,
        bomVersionNumber,
        quantity,
        lineName,
        lineCode,
        workshopCode,
        workshopName,
      } = data[0];
      // 调试完成记得删除控制台打印
      // console.log("选中数据", data);
      // 这里可以自定义返回字段信息
      // 第一个入参为当前表单绑定的对象，第二个入参为要修改的字段名，第三个入参为选中数据中相应信息
      const orderPlanEndDate = data[0].planEndDate; //订单结束时间
      this.$set(this.formDataDialog, "planCode", planCode);
      this.$set(this.formDataDialog, "saleCode", saleCode);
      const { planEndDate } = this.formDataDialog;
      this.$set(this.formDataDialog, "orderPlanEndDate", orderPlanEndDate);

      if (orderPlanEndDate && planEndDate) {
        if (
          new Date(planEndDate).getTime() > new Date(orderPlanEndDate).getTime()
        ) {
          this.$message.error(
            `${$i18n.t("mesProdOrder.dateLimit")} ${orderPlanEndDate}`
          );
          this.$set(this.formDataDialog, "planEndDate", null);
        }
      }

      //产品编码、生产工单类型、交货期、交货期宽裕天数控件不可编辑
      this.formDataDialog.prodCode = prodCode;
      this.formDataDialog.prodName = prodName;
      this.formDataDialog.prodOrderType = prodOrderType;
      this.formDataDialog.deliveryDate = deliveryDate;
      this.formDataDialog.slackTime = slackTime;
      this.formDataDialog.seriesName = seriesName;
      this.formDataDialog.seriesCode = seriesCode;
      this.formDataDialog.unit = unit;
      this.formDataDialog.unitCode = unitCode;
      this.formDataDialog.batchNo = batchNo;
      this.formDataDialog.bomVersionNumber = bomVersionNumber;
      this.formDataDialog.quantity = quantity;
      if (workshopCode) {
        this.$set(this.formDataDialog, "workshopCode", workshopCode); //单位
        this.$set(this.formDataDialog, "workshopName", workshopName); //单位
      } else {
        this.$set(this.formDataDialog, "workshopName", ""); //单位
        this.$set(this.formDataDialog, "workshopCode", ""); //单位
      }
      if (lineCode) {
        this.$set(this.formDataDialog, "lineCode", lineCode); //单位
        this.$set(this.formDataDialog, "lineName", lineName); //单位
      } else {
        this.$set(this.formDataDialog, "lineCode", ""); //单位
        this.$set(this.formDataDialog, "lineName", ""); //单位
      }
    },
  },
};
